home *** CD-ROM | disk | FTP | other *** search
- /*________________________________________________________
-
- File: Back2Front.c
-
- C code for a page-reversing printing extension.
-
- Dave Hersey
- Apple Developer Technical Support
-
- 3/22/94 - dmh - Created.
-
- (Note: all functions are in the Mark menu.)
-
- __________________________________________________________*/
-
- #include "Back2Front.h"
-
-
- /*******************************************************************
- InitGlobalData is used to initialize any global data we need to
- in our initialize message override. It's critical that you do
- things this way, rather than access the data in the same scope
- that you call NewMessageGlobals. Otherwise, some compilers
- will give you code that references an invalid A5 world.
-
- ********************************************************************/
-
- OSErr InitGlobalData()
- {
- // Initialize any global data here.
-
- return noErr;
- }
-
-
- /*******************************************************************
- NewInitialize is our override for the GXInitialize message. In
- here, you shouldn't initialize anything directly-- call
- InitGlobalData for that. Once you create the A5 world with
- NewMessageGlobals, you can access your global data just like
- you were an application. Whenever you're called, your global
- data will be valid.
-
- ********************************************************************/
-
- OSErr NewInitialize()
- {
- OSErr err;
-
- // Create an A5 world, and initialize our global data.
-
- err = NewMessageGlobals(A5Size(), A5Init);
-
- if (!err) err = InitGlobalData();
-
- return err;
- }
-
-
- /*******************************************************************
- NewShutDown is our override for the GXShutDown message. We
- simply throw away our A5 world which we created in our
- GXInitialize message override, NewInitialize.
-
- ********************************************************************/
-
- OSErr NewShutDown()
- {
- DisposeMessageGlobals();
- return noErr;
- }
-
-
- /*******************************************************************
- NewImageDocument is our override for the GXImageDocument
- message. We check to see if we're enabled, and if so, print
- our pages in the reverse order.
-
- ********************************************************************/
-
- OSErr NewImageDocument(gxSpoolFile aSpoolFile, void *imageData)
- {
- OSErr err = noErr;
- ExtensionCollection extCollect;
- gxFormat theFormat;
- long numPages;
- long i;
-
- // Try to retrieve our collection item. If we can't find it, we'll
- // act as if the user had us turned off or on (as determined by
- // kDefaultSetting).
-
- err = GetJobCollectionItem(&extCollect, nil, kExtensionCollectionType,
- gxPrintingTagID);
-
- if (err)
- {
- extCollect.extTurnedOn = kDefaultSetting;
- err = noErr;
- }
-
-
- // If we're turned on, print the pages in the reverse order.
- // Otherwise, just forward the message down the chain.
-
- if (extCollect.extTurnedOn)
- {
- theFormat = GXNewFormat(GXGetJob());
- err = Send_GXCountPages(aSpoolFile, &numPages);
-
- for (i = numPages; (err == noErr) && (i > 0); i--)
- err = Send_GXImagePage(aSpoolFile, i, theFormat, imageData);
-
- GXDisposeFormat(theFormat);
- }
- else
- err = Forward_GXImageDocument(aSpoolFile, imageData);
-
- return err;
- }
-
-
- /*******************************************************************
- NewJobPrintDialog is our override for GXJobPrintDialog. All we
- do is set up our panel and then forward the message.
-
- ********************************************************************/
-
- OSErr NewJobPrintDialog(gxDialogResult *dlogResult)
- {
- OSErr err;
-
- err = SetUpPrintPanel();
-
- if (!err)
- err = Forward_GXJobPrintDialog(dlogResult);
-
- return err;
- }
-
-
- /*******************************************************************
- SetUpPrintPanel sets up our print panel, adding a default
- ExtensionCollection item to the job collection. This
- collection item has the values we'll use to set up our panel's
- controls.
-
- ********************************************************************/
-
- OSErr SetUpPrintPanel()
- {
- OSErr err;
- gxPanelSetupRecord panelSetupRec;
- ExtensionCollection extConfig;
-
- // Try to find our collection item.
-
- err = GetCollectionItem(GXGetJobCollection(GXGetJob()),
- kExtensionCollectionType,
- gxPrintingTagID,
- nil,
- &extConfig);
-
-
- // If we don't have an item in the job collection yet, store our default
- // settings in it.
-
- if (err == collectionItemNotFoundErr)
- {
- extConfig.extTurnedOn = kDefaultSetting;
-
- err = AddCollectionItem(GXGetJobCollection(GXGetJob()),
- kExtensionCollectionType,
- gxPrintingTagID,
- sizeof(ExtensionCollection),
- &extConfig);
-
- nrequire(err, HaveCollectionMgrError);
- }
-
-
- // Now, set up the panel.
-
- panelSetupRec.panelResId = r_ExtensionPanel; // which panel resource?
- panelSetupRec.resourceRefNum = GXGetMessageHandlerResFile(); // where is it?
- panelSetupRec.refCon = 0; // we don't use this.
- panelSetupRec.panelKind = gxExtensionPanel; // This is an extension panel.
-
- err = GXSetupDialogPanel(&panelSetupRec);
-
-
- HaveCollectionMgrError:
-
- return err;
- }
-
-
- /*******************************************************************
- GetJobCollectionItem is a generic routine that retrieves a
- collection item from the job collection.
-
- ********************************************************************/
-
- OSErr GetJobCollectionItem(void *collectItem, long *collectSize,
- OSType collectType, short collectID)
- {
- return GetCollectionItem(GXGetJobCollection(GXGetJob()),
- collectType,
- collectID,
- collectSize,
- collectItem);
- }
-